package com.xf.conrroller;

import com.xf.entity.AjaxResult;
import com.xf.service.ExcelPoi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author fengjinhao
 * @date 2021/9/18 14:24
 */
@Slf4j
@RestController
@RequestMapping("/student")
@Api(tags = "学生相关")
public class StudentController {

    @Autowired
    private ExcelPoi excelPoi;


    @ApiOperation("学生导入")
    @PostMapping(value = "/import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public AjaxResult importExcelData(@RequestPart("file") MultipartFile file){

        try {
            return excelPoi.importStudent(file);
        } catch (Exception e) {
            log.error("数据导入异常：{}", ExceptionUtils.getStackTrace(e));
            return new AjaxResult().fail(e.getMessage()).cause(ExceptionUtils.getStackTrace(e));
        }
    }
}

